package com.pac.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.pac.MyApp;
import com.pac.R;
import com.pac.bean.homepage.Home;
import com.pac.bean.homepage.HomePageDaRenItem;
import com.pac.bean.homepage.HomePageHotItem;

import java.util.List;

/**
 * Created by Administrator on 2015/4/22.
 */
public class MyGridAdapter extends BaseAdapter {
    private Context context;
    private int i;
    LayoutInflater inflater;
    private Home d;
    private List<HomePageHotItem> datas;
    private List<HomePageDaRenItem> star;
    private String text;
    private String path;

    public MyGridAdapter(  Home d, Context context, int i) {
        this.d = d;
        this.context = context;
        this.i = i;
        init();
    }

    private void init() {
        if (i==0){
            datas=d.getHot();
        }else{
            star=d.getDaren();
        }
    }

    @Override
    public int getCount() {
        if (d!=null) {
            if (i == 0) {
                return datas.size();
            }
            else
            {
                return star.size();
            }
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if (i == 0) {
            return datas.get(position);
        }
        else
        {
            return star.get(position);
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        convertView=inflater.from(context).inflate(R.layout.home_viewpager,null);
        holder=new ViewHolder();
        holder.image= (ImageView) convertView.findViewById(R.id.home_viewpager_image);
        holder.text= (TextView) convertView.findViewById(R.id.home_viewpager_text);
        if (i==0){
            text = datas.get(position).getSubject();
            path=datas.get(position).getHost_pic();
        }else{
            text=star.get(position).getUser_name();
            path=star.get(position).getFace_pic();
            ViewGroup.LayoutParams params=holder.image.getLayoutParams();
            params.height=240;
            params.width=300;
            holder.image.setLayoutParams(params);
        }
        holder.text.setText(text);
        MyApp.myImageXutils.display(holder.image,path);
        return convertView;
    }
    class ViewHolder{
        ImageView image;
        TextView text;
    }
}
